<%@ page language="java" contentType="text/html; charset=UTF-8"	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
	String username = (String)session.getAttribute("username");	
	String vorname = (String)session.getAttribute("vorname");
	String name = (String)session.getAttribute("nachname");
%>
<!-- 
<script type="text/javascript" src="jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="jconfirmaction.jquery.js"></script>
 -->
<script type="text/javascript">
$(function() {
	$( "#accordion" ).accordion();
});

$(function() {
    $('#gallery a').lightBox();
});

$(function() {
	$("#datepicker").datepicker();
});

$(document).ready(
		function() {	
			// Das Element fÃ¼r die Anzeige suchen
		    var m = $("#map")[0];
		
			// Mittelpunkt der Karte
			var myLatlng = new google.maps.LatLng(48.84128, 12.9574);
		    var myOptions = {
		        // VergrÃ¶sserungsfaktor
		        // 0: Welt
		        // 1: Halbkugel
		        // [...]
		        // 16: Ein paar StraÃŸenzÃ¼ge
		        // 20: Voller Zoom
		        zoom:2,
		        // Zentrum setzen
		        center: myLatlng,
		        mapTypeId: google.maps.MapTypeId.ROADMAP
		    };
			map = new google.maps.Map(m, myOptions);
			
			
			//Sicherheitsabfrage: Datensatz wirklich loeschen
			$('.ask-plain').click(function(e) {
				
				e.preventDefault();
				thisHref	= $(this).attr('href');
				
				if(confirm('User wirklich loeschen ?')) {
					window.location = thisHref;
				}
				
			});
		}
	);

function wait(msecs) {
	var start = new Date().getTime();
	var cur = start
	while(cur - start < msecs) {
		cur = new Date().getTime();
	}	
} 

function setMarkerCity(city, street, title, couch, internet, stadt, parkplatz, id) {
	// Adresse zu LatLong
	var mygc = new google.maps.Geocoder();

	// Marker
	setTimeout(mygc.geocode({'address' : city + " , " + street}, function(results, status){
		if ( status == google.maps.GeocoderStatus.OK ) { 
			makeMarker({
				position: results[0].geometry.location,
				title: title, 
				content: "<div class=balloon><div class=state>" + 
							"<img src='img/couch" + couch + ".png'>" + 
							"<img src=img/internet" + internet + ".png>" + 
							"<img src=img/stadt" + stadt + ".png>" + 
							"<img src=img/parkplatz" + parkplatz + ".png>" + 
							"</div><h1>" + title + "</h1><h2>" + street + " in " + city + "</h2>" +
							<% if(username!=null) { %>
								"<p><a href='AnlegenAnfrage.html?id=" + id + "'>Anfrage senden</a></p>"
							<% } else { %>
								"<p><a href='Login.html'>Logge dich ein um eine Nachricht zu senden</a></p>"
							<% } %>
							+ "<div>" 
			});
		} else {
			alert ("DEBUG: (" + status + ") " + title + " " + street + " in " + city + " nicht gefunden")
		};
	}), 200 * id);
};

</script>
<c:forEach items="${personen}" var="person">
	<script>
		setMarkerCity("${person.ort}", "${person.adresse}", "${person.vorname} ${person.nachname}", "${person.getStateCouch().getId()}", "${person.getStateInternet().getId()}", "${person.getStateZeigeStadt().getId()}", "${person.getStateParkplatz().getId()}", "${person.id}");
	</script>
</c:forEach>
<c:out value="${msg}" />
<div id="map" class="map"></div>
<c:if test="${!empty errormsgUserRef}">
	<div title="Fehler" class="ui-dialog-content ui-widget-content fehler" id="dialog">
		<p>
			<span class="ui-icon ui-icon-alert"
				style="float: left; margin-right: .3em;"></span>
			<c:out value="${errormsgUserRef}" />
			<br>
			<c:out
				value="Soll der User mit allen zugehörigen Daten gelöscht werden?" />
		</p>
		<table>
			<tr>
				<td>
					<form method="get" action="LoeschePersonUndRef.html">
						<!--<c:out value="${delID}"/> -->
						<input type="hidden" name="delID"
							value='<c:out value="${delID}"/>' /> <input type="submit"
							value="Ja" />
					</form>
				</td>
				<td>
					<form method="get" action="AllePersonen.html">
						<input type="submit" value="Nein" />
					</form>
				</td>
			</tr>
		</table>
	</div>
</c:if>
<div id="accordion">
	<h3>
		<a href="#">Mitglieder</a>
	</h3>
	<div>
		<table class="listing">
			<colgroup>
				<col class="buttoncell" />
				<col class="buttoncell" />
				<col />
				<col />
			</colgroup>
			<tbody>
				<tr>
					<c:if test='${isLogUserAdmin == true}'>
						<!--  Diesen Bereich sollte nur der Admin sehen -->
						<th></th>
						<th></th>
					</c:if>
					<th></th>
					<th>Name</th>
					<th>Adresse</th>
					<th>Ort</th>
					<th class="">Bewertung</th>
					<th class="center">Anfragen</th>
					<% if(username!=null) { %>
						<th class="center">Anfrage senden</th>
					<% } %>
				</tr>
				<c:forEach items="${personen}" var="person">
					<tr>
						<!--  Diesen Bereich sollte nur der Admin sehen -->
						<c:if test='${isLogUserAdmin == true}'>
							<td><a
								href="changeUserDataAdmin.html?id=<c:out value='${person.id}'/>">
									<img src="img/pencil.png" alt="Bearbeiten" width="15">
							</a></td>
							<td>
								<!--  <a href="LoeschePerson.html?id=<c:out value='${person.id}'/>"> -->
								<a href="LoeschePerson.html?id=<c:out value='${person.id}'/>"
								class="ask-plain"> <img src="img/close.png" alt="Löschen"
									width="15">
							</a>
							</td>
						</c:if>
						<td><div id="gallery">
								<a href="img/unknown_user.gif"
									title="<c:out value="${person.vorname}"/> <c:out value="${person.nachname}"/>">
									<img src="img/unknown_user.gif" style="height: 20px;">
								</a>
							</div></td>
						<td><c:out value="${person.vorname}" /> <c:out
								value="${person.nachname}" /></td>
						<td><c:out value="${person.adresse}" /></td>
						<td><c:out value="${person.ort}" /></td>
						<td class=""><c:if test="${person.getAvgNote() != 0 }">
								<input class="star {split:2}" type="radio"
									name="durchschnitt<c:out value='${person.id}'/>"
									value=""
									disabled="disabled" />
								<input class="star {split:2}" type="radio"
									name="durchschnitt<c:out value='${person.id}'/>"
									value=""
									disabled="disabled"
									<c:if test="${person.getAvgNote() == 6 }">
								checked="checked"</c:if> />
								<input class="star {split:2}" type="radio"
									name="durchschnitt<c:out value='${person.id}'/>"
									value=""
									disabled="disabled"
									<c:if test="${person.getAvgNote() == 5.5 }">
								checked="checked"</c:if> />
								<input class="star {split:2}" type="radio"
									name="durchschnitt<c:out value='${person.id}'/>"
									value=""
									disabled="disabled"
									<c:if test="${person.getAvgNote() == 5 }">
								checked="checked"</c:if> />
								<input class="star {split:2}" type="radio"
									name="durchschnitt<c:out value='${person.id}'/>"
									value=""
									disabled="disabled"
									<c:if test="${person.getAvgNote() == 4.5 }">
								checked="checked"</c:if> />
								<input class="star {split:2}" type="radio"
									name="durchschnitt<c:out value='${person.id}'/>"
									value=""
									disabled="disabled"
									<c:if test="${person.getAvgNote() == 4 }">
								checked="checked"</c:if> />
								<input class="star {split:2}" type="radio"
									name="durchschnitt<c:out value='${person.id}'/>"
									value=""
									disabled="disabled"
									<c:if test="${person.getAvgNote() == 3.5 }">
								checked="checked"</c:if> />
								<input class="star {split:2}" type="radio"
									name="durchschnitt<c:out value='${person.id}'/>"
									value=""
									disabled="disabled"
									<c:if test="${person.getAvgNote() == 3 }">
								checked="checked"</c:if> />
								<input class="star {split:2}" type="radio"
									name="durchschnitt<c:out value='${person.id}'/>"
									value=""
									disabled="disabled"
									<c:if test="${person.getAvgNote() == 2.5 }">
								checked="checked"</c:if> />
								<input class="star {split:2}" type="radio"
									name="durchschnitt<c:out value='${person.id}'/>"
									value=""
									disabled="disabled"
									<c:if test="${person.getAvgNote() == 2 }">
								checked="checked"</c:if> />
								<input class="star {split:2}" type="radio"
									name="durchschnitt<c:out value='${person.id}'/>"
									value=""
									disabled="disabled"
									<c:if test="${person.getAvgNote() == 1.5 }">
								checked="checked"</c:if> />
								<input class="star {split:2}" type="radio"
									name="durchschnitt<c:out value='${person.id}'/>"
									value=""
									disabled="disabled"
									<c:if test="${person.getAvgNote() == 1 }">
								checked="checked"</c:if> />
							</c:if> <c:if test="${person.getAvgNote() == 0 }">
								noch keine Bewertungen</c:if></td>
						<td class="center"><c:out
								value="${person.getCountAnfragen()}" /></td>
						<% if(username!=null) { %>
							<td class="center">
								<a href="AnlegenAnfrage.html?id=${person.id}"><img src="img/mail.png" alt="Anfrage senden" height="15"></a>
							</td>
						<% } %>
					</tr>
				</c:forEach>
			</tbody>
		</table>
	</div>
	<h3>
		<a href="#">Legende</a>
	</h3>
	<div class="legende">
		<table>
			<tr>
				<td><img src="img/couch1.png"></td>
				<td><img src="img/couch2.png"></td>
				<td><img src="img/couch3.png"></td>
				<td><img src="img/couch4.png"></td>
			</tr>
			<tr>
				<td>belegt</td>
				<td>vielleicht verfügbar</td>
				<td>verfügbar</td>
				<td>nicht verfügbar</td>
			</tr>
		</table>
	</div>
</div>

<c:if test="${!empty errormsg}">
	<div title="Fehler" class="ui-dialog-content ui-widget-content fehler" id="dialog">
		<p>
			<span class="ui-icon ui-icon-alert"
				style="float: left; margin-right: .3em;"></span>
			<c:out value="${errormsg}" />
		</p>
	</div>
</c:if>

<c:if test="${!empty msg}">
	<div title="Nachricht" class="ui-dialog-content ui-widget-content nachricht" id="dialog">
		<p>
			<span class="ui-icon ui-icon-info"
				style="float: left; margin-right: .3em;"></span>
			<c:out value="${msg}" />
		</p>
	</div>
</c:if>